export const baseURL = 'http://localhost:5000'
// export const baseURL = 'http://192.168.43.113:5000'


export const request = (options) => {
	uni.showLoading({
		title: '加载中'
	})
	let url = baseURL + options.url
	const token = uni.getStorageSync('token')

	return new Promise((resolve, reject) => {
		uni.request({
			url: url,
			method: options.method || 'GET',
			data: options.data || {},
			header: {
				token
			},
			success(res) {
				if (res.data.code != 200) {
					return uni.showToast({
						title: res.data.msg,
						icon: 'none'
					})
				}
				resolve(res.data)
			},
			fail(err) {
				uni.showToast({
					title: '请求服务器失败!',
					icon: 'none'
				})
				reject(err)
			},
			complete() {
				uni.hideLoading()
			}
		})
	})
}
